package com.woniuxy.config;

import com.woniuxy.utils.String2DateConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: 马宇航
 * @Todo: 配置类
 * @DateTime: 22/04/07/0007 下午 4:13
 * @Component: 成都蜗牛学苑
 **/
@Configuration
public class MyConverter implements WebMvcConfigurer {
    //<bean id=“string2DateConverter 方法名” class=“com.woniuxy.utils.String2DateConverter”/>
    //注册成bean 还不够，之前我们还需要把这个bean对象注入到springmvc流程中
    @Bean
    public String2DateConverter string2DateConverter(){
        return new String2DateConverter();
    }
    //注册到SpringMVC环境中
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(string2DateConverter());
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //设置欢迎页面 thymeleaf 底层设置了视图解析器的前缀/templates和后缀.html
        registry.addViewController("/").setViewName("index");
        //设置生效的优先级
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }
}
